package com.hs.ph.Dao.Impl;

import com.hs.ph.Dao.UserDao;
import com.hs.ph.Entity.User;
import com.hs.ph.Utils.JDBCDruidUtil;

import java.sql.ResultSet;
import java.sql.SQLException;

public class UserDaoImpl implements UserDao {

    @Override
    public User selectByUsernameAndPwd(String username, String pwd) {
        String sql="select * from admin where username=? and pwd=?";
        Object [] obj=new Object[]{username,pwd};
        ResultSet res = JDBCDruidUtil.query(sql, obj);
        User user=null;
        while (true){
            try {
                if (!res.next()) break;
                user=new User(res.getInt("id"),res.getString("username"),res.getString("pwd"));
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }

        }
        JDBCDruidUtil.close();


        if (user!=null){
            return user;
        }
        return null;
    }
}
